/**
 * Common API for WEB EMS
 * 常用API
 * A . 页签常用操作
 * 1. initTabs()  : 主页签初始化
 * 2. createTab() : 新建页签
 * 3. selectTab() : 选定
 * 4. isExsitTab() : 判断是否存在
 *     
 * B. 树的操作
 * 1. initTree() : 初始化树
 * 
 * C.主菜单
 */

/**
 * 全局上下文
 */
var $ctx='/webbase';
var $ctxStatic=$ctx + '/static';

//进度条默认超时时间,单位秒
var PROGRESS_TIMEOUT = 30;
var LEFT_NAV_WIDTH = 230;
var isHideLeftNav = false;
//告警表格高度
var HEADER_HEIGHT = 35;
//告警表格弹出来最大高度
var MAX_OFFSET = 34;
var OplkEms = function(){	
	//Base Parameter
	this.IMG_WARN = $ctxStatic+'/images/warn.png';
	this.IMG_ERROR = $ctxStatic+'/images/error.png';
	this.IMG_INFO = $ctxStatic+'/images/info.png';
	this.IMG_LOADING = $ctxStatic+'/images/loading.gif';
	
	//================================================Menu Start===================================================//
	/**
	 * 初始化菜单栏,并侦听鼠标点击事件
	 */
	var that = this;
	this.initMenubar = function(){
		$(".nav-pills a[class='menu_item']").click(function() {	
			if(!$(this).attr('mid')){
				return;
			}
			that.createTab($(this).attr('mid'), this.innerText, $(this).attr('url'));
		});
	};	
	
	/**
	 * 检查指定网元槽位是否有板卡
	 * 返回类型：true   指定槽位存在板卡
	 *                 false  指定槽位不存在板卡
	 */
	this.neTable = {};
	this.isSlotOnBoard = function(neId, slotId){
		var ne = this.neTable[neId];
		if(ne != undefined || ne != null) {
			var slot = ne[slotId];
			if(slot == null) {
				return true;
			}
		}
		return false;
	};
	this.setNeTable = function(neId, slotTable) {
		this.neTable[neId] = slotTable;
	};
	this.getNeTable = function(){
		return $.isEmpty(this.neTable);
	};
	//================================================Menu End===================================================//
	
	/**
	 * ajax send
	 */
	this.send = function(url, data, func){
		 $.post(url,  data ,  func);
	};
	
	//=============================================JS Utils=======================//
	this.setSelectCtrl = function(item, value){
//		var itemName = item.name;
		$(item).find('option').each(function(index, data){
			if($(data).val() == value){
				$(data).attr('selected','selected');
				$(item).trigger('liszt:updated');
			}
		});
		/*$("[name="+itemName+"] option").each(function(index, data){			
			if(data.html() == value){
				data.attr('selected','selected');
				data.trigger('liszt:updated');
			}
		});*/
	};
	//================================================气泡弹出提示框============================================//
	/**
	 * 警告通知器
	 */
	this.warn = function(title, msg){
		$.gritter.add({
			title: title,
			text: msg,
			image: this.IMG_WARN,
			sticky: false,		
			class_name: 'gritter-info gritter-light'
		});
	};

	/**
	 * 消息通知器
	 */
	this.info = function(title, msg){
		$.gritter.add({
			title: title,
			text: msg,
			image: this.IMG_INFO,
			sticky: false,		
			class_name: 'gritter-info gritter-light'
		});
	};
	
	this.blink = function(item, beforeCss, afterCss) {
		var index = 0 ; 
		intervalId = 0;
		//闪烁
		intervalId = setInterval(function(){
			if(index%2==0){
				item.attr('class', afterCss);
			} else {
				item.attr('class', beforeCss);
			}
			
			if( index == 5 ) {
				clearInterval(intervalId);
			}
			index ++;
		}, 1000);
	};
	
	var intervalId = undefined;
	this.showWaiting = function(msg){
		//$('#modalProgress').modal('show');
		this.hideProgress();
		this.showProgress();
		var progress = $('#progressBar');
		$(progress).css('width', '0%');
		var text = $('#progressText');
		var timeIndex = 0;
		var progressData = 0;
		intervalId = setInterval(function(){
			$(progress).css('width', progressData+'%');			
			$(text).html(msg);			
			progressData += 10;
			timeIndex++;
			if(progressData == 100){
				progressData = 0;					
			}
		}, 1000);	
	};
	
	this.isShowProgress;
	this.hideProgress = function() {	
		if(this.isShowProgress) {
			$('#modalProgress').modal('hide');
			clearInterval(intervalId);
		}
		this.isShowProgress = false;
	};
	this.showProgress = function(msg){
		if(!this.isShowProgress) {
			if(msg != undefined) {
				$('#progressText').html(msg);
			}
			$('#modalProgress').modal('show');
		}
		this.isShowProgress = true;
		
		if(intervalId != undefined) {
			clearInterval(intervalId);
		}
	};
	/**
	 * 进度信息
	 */
	this.progress = function(progressData, msg, afterCall, paramDataList){		
		//this.showProgress();
		var progress = $('#progressBar');
		$(progress).css('width', '0%');
		
		var text = $('#progressText');
		var intervalId = undefined;
		
		var timeIndex = 0;
		var that = this;
		intervalId = setInterval(function(){
			$(progress).css('width', progressData+'%');			
			$(text).html(msg);
			if(timeIndex == PROGRESS_TIMEOUT){
				$(progress).css('width', '0%');
				$(text).html('初始化中......');
				clearInterval(intervalId);
				//$('#modalProgress').modal('hide');
				//that.hideProgress();
				afterCall.call(paramDataList[0], paramDataList[1]);
			}
			progressData += 10;
			timeIndex++;
		}, 1000);		
	};
	
	/**
	 * 进度信息
	 * ajaxSetting : 
	 * {url:xx, data:xx, function:xx}
	 */
	var intervalId = undefined;
	this.ajaxProgress = function(msg, ajaxSetting){
		var progressData = 0;
		//this.showProgress();
		var progress = $('#progressBar');		
		$(progress).css('width', '0%');
		var text = $('#progressText');
		var timeIndex = 0;
		intervalId = setInterval(function(){
			$(progress).css('width', progressData+'%');			
			$(text).html(msg);
			if(timeIndex == PROGRESS_TIMEOUT || progressData == 100){
				$(progress).css('width', '0%');
				$(text).html('初始化中......');
				clearInterval(intervalId);
				//that.hideProgress();
			}
			progressData += 10;
			timeIndex++;
		}, 1000);		
	
		/*$("#contentTable").ajaxStop(function(){
			clearInterval(intervalId);
			that.hideProgress();
		});*/
		$.ajax(ajaxSetting);
	};
	//================================================气泡弹出框End============================================//
	
	//================================================连接检查============================================//
	var isDisConnect = false;
	this.initConnCheck = function(){
		var that = this;
		setInterval(function(){
			$.ajax({url:_ctx+'/cfg/ne/ping',
				timeout:5000,
				success:function(){
					that.hideProgress();
					if(isDisConnect) {
						refreshAll();
					}
					isDisConnect = false;
				},
				error:function(xmlHttpRequest, error){
					if(!isDisConnect){
						that.showWaiting("系统掉线，重试中......");
					}
					isDisConnect = true;
				}});
		}, 10000);
	};
	//================================================连接检查END========================================//
	//================================================Accordian Start===================================================//
	/**
	 * 初始化左侧功能导航
	 */
	this.initAccordion = function(){
		//jquery accordion
		$( "#accordion" ).accordion({
			collapsible: true ,
			heightStyle: "content",
			animate: 250,
			header: ".accordion-header"
		}).sortable({
			axis: "y",
			handle: ".accordion-header",
			stop: function( event, ui ) {
				// IE doesn't register the blur when sorting
				// so trigger focusout handlers to remove .ui-state-focus
				ui.item.children( ".accordion-header" ).triggerHandler( "focusout" );
			}
		});
		
		/**
		 * 全屏模式
		 */
		this.previewMode = function() {			
			$('#leftContainer').css('display', 'none');
			$('#containerTable').css('display', 'none');
			/*$('#mainMenuBar').css('display', 'none');*/
			/*$('#mainContent').css('top', '0');*/
			$('#mainContent').css('left', '0');			
			$('#mainContent').css('height', '100%');
			$('#mainContent').css('width', '100%');
		};
		
		/**
		 *  工作模式
		 */
		this.workMode = function(){			
			$('#leftContainer').css('display','');
			$('#containerTable').css('display','');
			/*$('#mainMenuBar').css('display','');*/
			/*$('#mainContent').css('top', '54px');*/
			$('#mainContent').css('left', '6px');
			$('#mainContent').css('height', '650px');
			$('#mainContent').css('width', '75%');
		};
	//================================================Accordian End===================================================//	
		
	//================================================Tab Start===================================================//
	//主页签
	this.tabs = null;
	this.tabCounter = 0;
	/**
	 * 初始化主页面Tab
	 */
	this.initTabs = function(){
		this.tabs = $('#tab_nav').tabs();		
		this.setFirstTabActive();
	};
	
	/**
	 * 选择页签
	 */
	this.selectTab = function(tid){
		$(".nav-tabs a[href='#"+tid+"']").tab('show');
	};
	
	/**
	 * 检查是否存在Tab，如果存在，返回true。
	 * @param tid
	 */
	this.isExsitTab = function(tid) {
		return ($("div[id='"+tid+"']").length !=0 );
	};
	
	/**
	 * 设置最后一个tab为激活
	 */
	this.setLastTabActive = function(){
		$('.nav-tabs a:last').tab('show');
	};
	/**
	 * 设置第一个tab为激活状态
	 */
	this.setFirstTabActive = function(){
		$('.nav-tabs a:first').tab('show');
	};
	
	/**
	 * 创建页签
	 */
	this.createTab = function(id, title, url){
		if(!this.isExsitTab(id)) {
			//添加导航栏
			var li = "<li><a href='#"+id+"' data-toggle='tab'>"+title
			+"<span class='icon-remove'></span></a> </li>";
			this.tabs.append( li );
			//添加内容
			var tabContentHtml = "<iframe id='mainFrame' name='mainFrame' src='"+url+"'";
			tabContentHtml += " style='overflow: visible;' scroll='no' frameborder='no'";
			tabContentHtml += "	width='100%' height='578px;'></iframe>";
			var tabContent =  "<div class='tab-pane' id='" + id + "'>" 
									+ tabContentHtml + "</div>" ;
			$('#tab_cont').append(tabContent);			
			//显示当前最新添加页签。
			this.setLastTabActive();
			//注册关闭事件
			var that = this;
			$( "#tab_nav" ).on( "click",'span.icon-remove', function() {
				var itemLI = $( this ).closest( "li" );
				var panelId = itemLI.remove().attr( "aria-controls" );
				$( "#" + panelId ).remove();
				var tabId = $(itemLI).find('a').attr('href');
				$( tabId ).remove();
				that.setLastTabActive();
				that.tabs.tabs( "refresh" );
			});
			this.tabCounter++;
			//设置选中tab		
		} else {		
			this.selectTab(id);
		}
		this.tabs.tabs( "refresh" );
	};
	//========================================Tab END============================================//
	
	//=======================================Left Nav Handler=====================================//
	
	this.initLeftNavHandler = function(){
		var item = $('#leftNavHandler'); 
		item.click(function(){
			//第一次点击，缩回
			if(item.attr('select') == 'true'){
				$('#leftContainer').animate({marginLeft:"-219px"});			
				$('#leftNavFlag').html('>');
				
				var mWidth = $('#mainContent').css('width');
				mWidth = mWidth.replace('px','');				
				$('#mainContent').animate({width:parseInt(mWidth)+LEFT_NAV_WIDTH-16});
				item.attr('select', 'false');
				isHideLeftNav = true;
			} else {				
				var mWidth = $('#mainContent').css('width');
				mWidth = mWidth.replace('px','');
				$('#mainContent').animate({width:parseInt(mWidth)-LEFT_NAV_WIDTH+16});
				$('#leftContainer').animate({marginLeft:"-1px"});
				$('#leftNavFlag').html('<');
				item.attr('select', 'true');
				isHideLeftNav = false;
			}
		});
	};
	//=======================================Left Nav Handler End=================================//
	
	//=======================================Tree Start ===========================================//
	//操作树变量
	this.zTree = null;
	this.URL_TOPO = _ctxStatic + '/images/topo.png';
	this.URL_STATION = _ctxStatic + '/images/station.png';
	this.URL_NE = _ctxStatic + '/images/finder.png';
	this.URL_CARD = _ctxStatic + '/images/card.png';
	this.HIGH_LIGHT_COLOR = '#FF0000';
	//针对标签 <wiget:module>
	this.INITIAL_MAP = {};
	this.lastValue = "";
	this.nodeList = [];
	this.fontCss = {};
	//测试模型
	this.zNodes = [ {
		id : 0,
		pId : -1,
		name : "网络拓扑",
		t : "网络拓扑",
		type : 'root',
		open : true,
		icon : this.URL_TOPO
	}, {
		id : 1,
		pId : 0,
		name : "武昌站点",
		t : "武昌站点",
		type : 'station',
		open : true,
		icon : this.URL_STATION
	}, {
		id : 6,
		pId : 1,
		name : "网元01",
		t : "网元01",
		type : 'ne',
		open : true,
		icon : this.URL_NE
	}, {
		id : 8,
		pId : 6,
		name : "CCAV板卡",
		t : "CCAV板卡",
		tempture : '33℃',
		status:'online',
		type : 'card',
		open : true,
		icon : this.URL_CARD
	}, {
		id : 9,
		pId : 6,
		name : "EDFA PB板卡",
		t : "查看EDFA PB板卡",
		tempture : '32℃',
		status:'online',
		type : 'card',
		open : true,
		icon : this.URL_CARD
	}, {
		id : 7,
		pId : 1,
		name : "网元02",
		t : "网元02",
		type : 'ne',
		open : true,
		icon : this.URL_NE
	},

	{
		id : 2,
		pId : 0,
		name : "汉阳站点",
		t : "汉阳站点",
		type : 'station',
		open : true,
		icon : this.URL_STATION
	}, {
		id : 10,
		pId : 2,
		name : "网元01",
		t : "网元01",
		type : 'ne',
		open : true,
		icon : this.URL_NE
	}, {
		id : 11,
		pId : 2,
		name : "网元02",
		t : "网元02",
		type : 'ne',
		open : true,
		icon : this.URL_NE
	}, {
		id : 18,
		pId : 11,
		name : "ByPass板卡",
		t : "查看ByPass板卡",
		tempture : '22℃',
		status:'online',
		type : 'card',
		open : true,
		icon : this.URL_CARD
	}, {
		id : 19,
		pId : 11,
		name : "EDFA PA板卡",
		t : "查看EDFA PA板卡",
		tempture : '20℃',
		status:'online',
		type : 'card',
		open : true,
		icon : this.URL_CARD
	},

	{
		id : 3,
		pId : 0,
		name : "郑州NP1站点",
		t : "郑州NP1站点",
		type : 'station',
		open : true,
		icon : this.URL_STATION
	}, {
		id : 12,
		pId : 3,
		name : "网元01",
		t : "网元01",
		type : 'ne',
		open : true,
		icon : this.URL_NE
	}, {
		id : 20,
		pId : 12,
		name : "ByPass板卡",
		t : "查看ByPass板卡",
		type : 'card',
		tempture : '19℃',
		status:'offline',
		open : true,
		icon : this.URL_CARD
	}, {
		id : 21,
		pId : 12,
		name : "EDFA PA板卡",
		t : "查看EDFA PA板卡",
		tempture : '28℃',
		status:'online',
		type : 'card',
		open : true,
		icon : this.URL_CARD
	},

	{
		id : 13,
		pId : 3,
		name : "网元02",
		t : "网元02",
		type : 'ne',
		open : true,
		icon : this.URL_NE
	}, {
		id : 22,
		pId : 13,
		name : "ByPass板卡",
		t : "查看ByPass板卡",
		tempture : '45℃',
		status:'online',
		type : 'card',
		open : true,
		icon : this.URL_CARD
	}, {
		id : 23,
		pId : 13,
		name : "EDFA PA板卡",
		t : "查看EDFA PA板卡",
		type : 'card',
		tempture : '25℃',
		status:'online',
		open : true,
		icon : this.URL_CARD
	},

	{
		id : 4,
		pId : 0,
		name : "湖南NP2站点",
		t : "湖南NP2站点",
		type : 'station',
		open : true,
		icon : this.URL_STATION
	}, {
		id : 14,
		pId : 4,
		name : "网元01",
		t : "网元01",
		type : 'ne',
		open : true,
		icon : this.URL_NE
	}, {
		id : 15,
		pId : 4,
		name : "网元02",
		t : "网元02",
		type : 'ne',
		open : true,
		icon : this.URL_NE
	},

	{
		id : 5,
		pId : 0,
		name : "江苏NP1站点",
		t : "江苏NP1站点",
		type : 'ne',
		open : true,
		icon : this.URL_STATION
	}, {
		id : 16,
		pId : 5,
		name : "网元01",
		t : "网元01",
		type : 'ne',
		open : true,
		icon : this.URL_NE
	}, {
		id : 17,
		pId : 5,
		name : "网元02",
		t : "网元02",
		type : 'ne',
		open : true,
		icon : this.URL_NE
	}, ];
  
  this.setting = {
		data : {
			key : {
				title : "t"
			},
			simpleData : {
				enable : true
			}
		},
		view : {
			fontCss : {}
		},
		callback : {
			onDblClick : {}
		}
	};
  
	/**
	 * 初始化树
	 */
  	this.getTreeSiteId = function(treeId) {
  		return treeId.substring(0, treeId.indexOf('_'));
  	};
  	this.getTreeNeId = function(treeId) {
  		return treeId.substring(treeId.indexOf('_')+1, treeId.lastIndexOf('_'));
  	};
  	this.getTreeSlotId = function(treeId) {
  		return treeId.substr(treeId.lastIndexOf('_')+1);
  	};
  	
	this.initTree = function(isExpand) {
		//针对初始化无法赋值的情况
	/*	this.setting.callback.onDblClick = this.onTreeItemDblClick;
		this.setting.callback.onClick = this.onTreeItemClick;
		this.setting.view.fontCss = this.getFontCss;
		
		$.fn.zTree.init($("#treeTopoResouce"), this.setting, this.zNodes);
		this.zTree = $.fn.zTree.getZTreeObj("treeTopoResouce");
		this.zTree.expandAll(false);*/
		//默认是否展开
		isExpand = (isExpand == undefined ) ? false : true;
		$.get(_ctx + '/sys/config/listDTO', function(result){
			//初始化树
			var tree = new Tree();
			tree.initTree('treeTopoResouce', result);			
			//展开指定节点。
			tree.zTree.expandAll(false);
			//高亮指定节点
			if($("[name='id']").val() != undefined){
				tree.searchNode($("[name='parentId']").val());
			}
			that.tree = tree;
		});
		
	};
	
	this.lstSelectedItem = null;
	this.setLstItem = function(item){
		this.lstSelectedItem = item;
	};
	
	this.getLstItem = function(){
		return this.lstSelectedItem;
	};
	
	this.updateAvailbleSlot = function(item){
		if(item!=null) {
			that.tree.updateAvailbleSlot(item);
		}
	};
	
	this.expandTree = function(){
		that.zTree = $.fn.zTree.getZTreeObj("treeTopoResouce");
		that.zTree.expandAll(true);
	};
	
	/**
	 * 单击树，更新状态栏
	 */
	this.onTreeItemClick = function(event, treeId, treeNode, clickFlag){
		 if(treeNode.type=='card') {
			 $('#statusCardName').html("<b>名称</b>&nbsp;:&nbsp;<a class='text-success'>" + treeNode.name+"</a");
			 $('#statusCardTemp').html("<b>温度</b>&nbsp;:&nbsp;<a class='text-success'>" + treeNode.tempture+"</a");
			 if(treeNode.status=='offline') {
				 $('#statusCardStatus').html("<b>状态</b>:&nbsp;&nbsp;&nbsp;<span class='label label-green'>在线</span>");
			 } else if(treeNode.status=='online'){
				 $('#statusCardStatus').html("<b>状态</b>:&nbsp;&nbsp;&nbsp;<span class='label label-grey'>离线</span>");
			 }
		}
	};
	
	/**
	 * 点击树节点事件
	 * @param event
	 * @param treeId
	 * @param treeNode
	 * @param clickFlag
	 */
	this.onTreeItemDblClick = function(event, treeId, treeNode, clickFlag){
		//打开网元节点
		if(treeNode.type=='ne') {
			that.createTab(treeNode.id, treeNode.t, '/webbase/core/index/neChassis');
		//如果是根节点，则不创建tab，只创建网元，板卡的tab		
		} else if(treeNode.type=='root') {
			that.selectTab('tabs-topo');
		//打开板卡
		} else if(treeNode.type=='card') {
			that.createTab(treeNode.id, treeNode.t, '/webbase/core/index/cardConfig');
		}
	};

	/**
	 * 搜索树节点
	 * 
	 * @param value
	 */
	this.searchNode = function(value) {
		var keyType = "";
		keyType = "id";
		//value = parseInt(value);
		if (this.lastValue === value)
			return;
		this.lastValue = value;
		if (value === "")
			return;
		this.updateNodes(false);

		var node = this.zTree.getNodeByParam(keyType, value);
		if (node === null) {
			this.nodeList = [];
		} else {
			this.nodeList = [ node ];
		}
		
		this.updateNodes(true);
	};
	this.updateNodes = function(highlight) {
		this.zTree = $.fn.zTree.getZTreeObj("treeTopoResouce");
		for ( var i = 0, l = this.nodeList.length; i < l; i++) {
			this.nodeList[i].highlight = highlight;
			this.zTree.updateNode(this.nodeList[i]);
		}
	};

	this.getFontCss = function(treeId, treeNode) {
		return (!!treeNode.highlight) ? {
			color : that.HIGH_LIGHT_COLOR,
			"font-weight" : "bold"
		} : {
			color : "#333",
			"font-weight" : "normal"
		};
	};

	this.filter = function(node) {
		return !node.isParent && node.isFirstNode;
	};
	//=======================================Tree End ===========================================//
	//=======================================Resize Listener=======================================//
	this.updateWindow = function(windowWidth, windowHeight){
		
	};
	
	this.updateAlartTable = function() {
		var MAIN_ALERT_TABLE = $('#containerTable');
		var TABLE_ICON = $('#tableIcon');
		//全局拖动窗体事件
		var windowHeight = $(window).innerHeight();
		if(windowHeight < 680) {
			//悬浮弹出
			MAIN_ALERT_TABLE.css('position','fixed');
			MAIN_ALERT_TABLE.css('z-index','13');
			MAIN_ALERT_TABLE.css('width','100%');
			
			var offset = parseInt($('#contentTable').css('height').replace('px',''));
			if( (offset+HEADER_HEIGHT) > MAX_OFFSET ) {
				MAIN_ALERT_TABLE.css('bottom', -(offset+HEADER_HEIGHT)+'px');
			} else {
				MAIN_ALERT_TABLE.css('bottom', MAX_OFFSET+'px');
			}
			TABLE_ICON.css('display','');
			$('#tableHandler').css('display','');
		} else {
			//悬浮隐藏
			MAIN_ALERT_TABLE.css('position','');
			MAIN_ALERT_TABLE.css('z-index','12');
			MAIN_ALERT_TABLE.css('width','100%');
			MAIN_ALERT_TABLE.css('bottom','-35px');
			TABLE_ICON.css('display','none');
			$('#tableHandler').css('display','none');
		}
	};
	
	/**
	 * 初始化控件配置信息
	 */
	this.initContrlConfig = function(){
		/*$.fn.datepicker.dates['zh-CN'] = {
			    days: ["星期天", "星期一", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
			    daysShort: ["星期天", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
			    daysMin: ["日", "一", "二", "三", "四", "五", "六", "天"],
			    months: ["一月", "二月", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
			    monthsShort: ["一月", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
			    today: "今天",
			    clear: "清除"
			};*/
	};
	
	/**
	 * 全局窗口事件
	 */
	this.initWindowEvent = function(){
		var TABLE_HANDLER = $('#tableHandler');
		//全局拖动窗体事件
		var that = this;
		window.onresize =  function(){
			var windowWidth = $(window).innerWidth(); 
			that.updateWindow();
			that.updateAlartTable();
			//如果左侧导航栏缩进去，则减去20px
			if(isHideLeftNav) {
				$('#mainContent').css('width', (windowWidth-20+'px'));
			} else {
				$('#mainContent').css('width', (windowWidth-234+'px'));
			}
		};
		
		/**
		 * 注册弹出按钮事件
		 */
		TABLE_HANDLER.click(function(){
			var isSelected = $(this).attr('select');
			var offset = parseInt($('#contentTable').css('height').replace('px',''));
			if(isSelected == 'false') {	
				//点击按钮缩回去			
				$('#containerTable').animate({bottom: -HEADER_HEIGHT+"px"});											
				$('#tableIcon').removeClass('icon-upload-alt').addClass('icon-download-alt');		
				$(this).attr('select', 'true');
			}else{
				//点击按钮弹出来
				//table.css('bottom','-35px');
				if( (offset+HEADER_HEIGHT) > MAX_OFFSET ) {
					$('#containerTable').animate({bottom:'-255px'});
				} else {
					$('#containerTable').animate({bottom:-(offset+HEADER_HEIGHT)+'px'});
				}
				$('#tableIcon').removeClass('icon-download-alt').addClass('icon-upload-alt');			
				$(this).attr('select', 'false');
			}
		});
		
		//初始化主工作区宽度
		$('#mainContent').css('width', ($(window).innerWidth()-234+'px'));
		//初始化按钮
		this.updateAlartTable();
	};
	
	//=======================================Resize Listener End ==================================//
	//=======================================Table Start =========================================//
	/**
	 * 初始化表格事件
	 */
	this.initTable = function(){
		var that = this;
		//注册表格行双击事件。
		$('#contentTable tr').each(function(index,item){
			$(item).dblclick(function(e) {
				var cell = $(this).find('td');
				var ids = cell.eq(9)[0].innerText;					
				//展开指定节点。
				that.zTree = $.fn.zTree.getZTreeObj("treeTopoResouce");
				that.zTree.expandAll(true);
				//高亮指定节点
				that.searchNode(ids);
			});
			
			var linkOper = $(this).find('td').eq(8);
			linkOper.click(function(){
				commonAPI.createTab('21','当前告警同步','/webbase/alarm/alarmcur');
			});
		});
	};
	//=======================================Table End ========================================//
};
};
